package com.qdhh.enrollment.security;

import cn.dev33.satoken.stp.StpUtil;
import com.qdhh.enrollment.common.BusinessException;

/**
 * 权限检查工具类
 * 提供身份认证相关的静态方法
 */
public class PermissionChecker {

    /**
     * 检查当前用户是否已进行身份认证
     * @return true 如果已认证，false 如果未认证
     */
    public static boolean isIdentityVerified() {
        if (!StpUtil.isLogin()) {
            return false;
        }
        
        Object identityVerifiedObj = StpUtil.getSession().get("identityVerified");
        Integer identityVerified = identityVerifiedObj != null ? (Integer) identityVerifiedObj : 0;
        
        return identityVerified != null && identityVerified == 1;
    }

    /**
     * 检查当前用户是否已进行身份认证，未认证则抛出异常
     * @throws BusinessException 如果未认证
     */
    public static void checkIdentityVerified() {
        if (!isIdentityVerified()) {
            throw new BusinessException("需要身份认证");
        }
    }
}

